/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.Utilities
*        文件名:             BaseSortLogic.cs
*        创建系统时间:       2012/11/2 19:07:08
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.Utilities
{
    using System.Data;

    public class BaseSortLogic
    {
        public static string GetNextID(DataTable dataTable, string id)
        {
            return GetNextID(dataTable.DefaultView, id, BaseBusinessLogic.FieldID);
        }

        public static string GetNextID(DataView dataView, string id)
        {
            return GetNextID(dataView, id, BaseBusinessLogic.FieldID);
        }

        public static string GetNextID(DataTable dataTable, string id, string field)
        {
            return GetNextID(dataTable.DefaultView, id, field);
        }

        public static string GetNextID(DataView dataView, string id, string field)
        {
            string str = string.Empty;
            bool flag = false;
            foreach (DataRowView view in dataView)
            {
                if (flag)
                {
                    return view[field].ToString();
                }
                if (view[field].ToString().Equals(id))
                {
                    flag = true;
                }
            }
            return str;
        }

        public static string GetPreviousID(DataTable dataTable, string id)
        {
            return GetPreviousID(dataTable.DefaultView, id, BaseBusinessLogic.FieldID);
        }

        public static string GetPreviousID(DataView dataView, string id)
        {
            return GetPreviousID(dataView, id, BaseBusinessLogic.FieldID);
        }

        public static string GetPreviousID(DataTable dataTable, string id, string field)
        {
            return GetPreviousID(dataTable.DefaultView, id, field);
        }

        public static string GetPreviousID(DataView dataView, string id, string field)
        {
            string str = string.Empty;
            foreach (DataRowView view in dataView)
            {
                if (view[field].ToString().Equals(id))
                {
                    return str;
                }
                str = view[field].ToString();
            }
            return str;
        }

        public static int Swap(DataTable dataTable, string id, string targetID)
        {
            string targetValue = BaseBusinessLogic.GetProperty(dataTable, id, BaseBusinessLogic.FieldSortCode);
            string str2 = BaseBusinessLogic.GetProperty(dataTable, targetID, BaseBusinessLogic.FieldSortCode);
            return (BaseBusinessLogic.SetProperty(dataTable, id, BaseBusinessLogic.FieldSortCode, str2) + BaseBusinessLogic.SetProperty(dataTable, targetID, BaseBusinessLogic.FieldSortCode, targetValue));
        }
    }
}